compiler: Guard cond_mapper lookup in halo hoisting (fix nested HaloSpot KeyError)#2944
compiler: Guard cond_mapper lookup in halo hoisting (fix nested HaloSpot KeyError)#2944ggorman wants to merge 1 commit into
Conversation
_hoist_redundant_from_conditionals iterated every halo_spot from _filter_iter_mapper and did an unguarded cond_mapper[hs0], which raised KeyError for a nested HaloSpot (one whose subtree contains another HaloSpot), since _make_cond_mapper does not register nested HaloSpots as keys. Use the defensive cond_mapper.get(hs0) (as already done in _merge_halospots); the existing 'if not conditions: continue' handles the absent-key case. Fixes #2943.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2944 +/- ##
=======================================
Coverage 83.44% 83.44%
=======================================
Files 249 249
Lines 52203 52203
Branches 4496 4496
=======================================
+ Hits 43560 43562 +2
+ Misses 7883 7882 -1
+ Partials 760 759 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
FabioLuporini
left a comment
There was a problem hiding this comment.
raising KeyError for a nested HaloSpot (one whose subtree contains another HaloSpot)
why would there be nested HaloSpots -- that's the true culprit AI is failing to understand here
we're going to need a 10 lines reproducer
|
Thanks @FabioLuporini — fair question why a nested HaloSpot exists at all, so let me start there, then give you the short reproducer, then come back to whether Where this came fromWe hit this while implementing the staggered summation-by-parts (SBP-SAT) Why there is a nested HaloSpotI traced the IET. It is genuinely nested, and I now think the nesting itself is a At the IET level, the offending Operator's tree contains an outer The crash is an asymmetry between the two mappers the pass builds from the same
for hs0 in halo_spots:
conditions = cond_mapper[hs0] # KeyError: nested HaloSpot is not a keyThe nested So to answer "why would there be nested HaloSpots": they arise whenever several It reproduces on 4.8.21 and on current Minimal reproducer (~16 lines)Two accumulator families ( from devito import Grid, Function, Eq, Operator, SubDomain
n, nr = 10, 2
def mk(nm, tx, ty):
return type(nm, (SubDomain,), {"name": nm,
"define": lambda self, d: {d[0]: tx, d[1]: ty}})()
th = [("middle", i, n - 1 - i) for i in range(nr)] + [("middle", nr, nr)]
subs = [mk(f"z{i}_{j}", th[i], th[j]) for i in range(nr + 1) for j in range(nr + 1)]
grid = Grid(shape=(n, n), subdomains=tuple(subs))
x, y = grid.dimensions
A, B = Function(name="A", grid=grid), Function(name="B", grid=grid)
a1, a2 = Function(name="a1", grid=grid), Function(name="a2", grid=grid)
eqs = [Eq(a1, A[x + 1, y] + (B[x + 2, y] if i >= 1 else 0), subdomain=subs[i * (nr + 1) + j])
for i in range(nr + 1) for j in range(nr + 1)]
eqs += [Eq(a2, A[x - 1, y] + (B[x + 3, y] if i >= 2 else 0), subdomain=subs[i * (nr + 1) + j])
for i in range(nr + 1) for j in range(nr + 1)]
Operator(eqs)() # default opt -> KeyError; Operator(eqs, opt='noop') worksTraceback (on I've reduced from 9 to 4 Is
|
|
you crazy if you think I read that entire thing 😂 |
|
in that MFE, what does the https://github.com/devitocodes/devito/blob/main/devito/ir/clusters/algorithms.py#L53 |
|
At
So it's 18 same-iteration-space, per- |
Fixes #2943.
_hoist_redundant_from_conditionals(devito/passes/iet/mpi.py) iterated every halo_spot from_filter_iter_mapperand did an unguardedcond_mapper[hs0], raisingKeyErrorfor a nested HaloSpot (one whose subtree contains another HaloSpot) —_make_cond_mapperdoes not register nested HaloSpots as keys. This switches to the defensivecond_mapper.get(hs0)already used in_merge_halospots; the existingif not conditions: continuehandles the absent-key case, so behaviour is preserved for present keys.Minimal reproducer + before/after output are in #2943. The reproducer also verifies this exact fix by monkeypatching
_make_cond_mapperto return adefaultdict(list). Confirmed on currentmain.Happy to add a regression test under
tests/if you'd like — let me know the preferred home (it needs a nested-HaloSpot SubDomain layout).